﻿<%@ Control Language="C#" AutoEventWireup="true" Inherits="HL.Lib.MVC.ViewControl" %>
<% var listItem = ViewBag.Data as List<ModPropertyEntity>;
   List<ModPropertyEntity> listChild = null;
   var Title = ViewBag.Title as string;
%>
<script runat="server">
    int[] arrPropertyID = null;
    string atr = null;
    string current_url = null;
    bool se = false;
    bool select = false;
    protected void Page_Load(object sender, EventArgs e)
    {
        atr = ViewPage.ViewBag.Filter;
        if (!string.IsNullOrEmpty(atr))
            arrPropertyID = HL.Core.Global.Array.ToInts(atr.Split('-'));
        current_url = ViewPage.GetPageURL(ViewPage.CurrentPage);
        if (arrPropertyID != null) se = true;
    }   
</script>

    <p class="searchtt conner4">
        <%=Title %></p>
    <%if (listItem != null && listItem.Count > 0)
      { %>
    <div class="search">
        <%for (int i = 0; i < listItem.Count; i++)
          {
              listChild = ModPropertyService.Instance.CreateQuery()
                  .Where(o => o.ParentID == listItem[i].ID)
                  .ToList();
              if (listChild != null)
              { %>
        <%--        <p>
            <label>
                <%=listItem[i].Name %></label>
            <select name="combo">
                <option value="0">Tất cả</option>
                <%for (int j = 0; listChild != null && j < listChild.Count; j++)
                  {
                      if (se && Array.IndexOf(arrPropertyID, listChild[j].ID) > -1) select = true; else select = false;
                %>
                <option value="<%=listChild[j].ID %>" <%if(select){ %>selected<%} %>>
                    <%=listChild[j].Name %></option>
                <%} %>
            </select></p>--%>
        <div class="search_b clearfix">
            <label><%=listItem[i].Name %></label>
            <select name="combo" id="filter<%=i %>" style="width: 162px;" tabindex="1">
                <option value="0">Tất cả</option>
                <%for (int j = 0; listChild != null && j < listChild.Count; j++)
                  {
                      if (se && Array.IndexOf(arrPropertyID, listChild[j].ID) > -1) select = true; else select = false;
                %>
                <option value="<%=listChild[j].ID %>" <%if(select){ %>selected<%} %>>
                    <%=listChild[j].Name %></option>
                <%} %>
            </select>
            <script type="text/javascript">
                $(document).ready(function () {

                    try {
                        $("#filter<%=i %>").msDropDown({ mainCSS: 'dd2' });
                        //alert($.msDropDown.version);
                        //$.msDropDown.create("body select");
                        $("#ver").html($.msDropDown.version);
                    } catch (e) {
                        alert("Error: " + e.message);
                    }
                })

            </script>
        </div>
        <%}
          } %>
        <p>
            <a class="search_bt conner4" href="javascript:;" onclick="Filter();">Tìm</a></p>
    </div>
    <%} %>
<script type="text/javascript">
    var surl = '';
    var count = 0;
    function OnchangeClick() {
        count++;
    }
    function Filter() {
        var arr_com = document.getElementsByName('combo');
        for (var i = 0; i < arr_com.length; i++) {
            if (arr_com[i].value > 0) {
                surl += (surl == '' ? '' : '-') + arr_com[i].value;
            }
        }
        if (surl == '' && count == 0) surl = '<%=atr %>';
        if (surl == '') alert('Chọn các tiêu chí tìm kiếm !');
        else {

            location.href = '<%=current_url %>?Filter=' + surl;
        }
    }
</script>
